/**
 * Authors:
 * Vladimír Matěna
 * Jan Skalický
 */
package inireader;

/**
 * Class used for limiting values of property elements. Limits range of value.
 */
public final class RangeRestriction extends Restriction
{
	private double lowerBound, upperBound;

	/**
	 * Creates RangeRestriction.
	 * @param lowerBound min value
	 * @param upperBound max value
	 * @param property for this property
	 */
	public RangeRestriction(double lowerBound, double upperBound, Property property)
	{
		super(property);
		
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
	}

	/**
	 * Validates value, in case of bad formatting throws exception.
	 * @param value value to validate
	 */
	public void validateRestrictedValue(String value)
	{
		double valueDouble = Double.valueOf(value);

		if (lowerBound < valueDouble || valueDouble > upperBound)
		{
			throw new ValidatingException(String.format("Value %s is out of permitted bounds in property %s!", value, property.getName().getId()));
		}
	}
}
